package com.ysalliance.getFan.organization.adapter;


import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.Utils;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.ysalliance.getFan.organization.Bean.TaskBean;
import com.ysalliance.getFan.organization.Bean.multilist.FirstTimeBean;
import com.ysalliance.getFan.organization.R;
import com.ysalliance.getFan.organization.ui.h5.CommonH5Activity;
import com.ysalliance.getFan.organization.ui.h5.TaskH5Activity;

import java.util.List;

import androidx.annotation.Nullable;

import static com.ysalliance.getFan.organization.FanerConstant.AGREEMENT;
import static com.ysalliance.getFan.organization.FanerConstant.TASKDETAIL;


public class TaskMultiListAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    public static final int ITEM_FIRST_LEVEL = 1;
    public static final int ITEM_SECOND_LEVEL = 2;


    public TaskMultiListAdapter(@Nullable List<MultiItemEntity> data) {
        super(data);

        addItemType(ITEM_FIRST_LEVEL, R.layout.item_multilist_time);
        addItemType(ITEM_SECOND_LEVEL, R.layout.item_multilist_task);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case ITEM_FIRST_LEVEL:
                final FirstTimeBean item_temp = (FirstTimeBean) item;
                helper.setText(R.id.tv_class_time, item_temp.getCreate_time());

//                //点击隐藏和展开二级列表
//                helper.itemView.setOnClickListener(v -> {
//                    int pos = helper.getAdapterPosition();
//                    if (item_temp.isExpanded()) {
//                        collapse(pos);
//                    } else {
//                        expand(pos);
//                    }
//                });

                //各种处理数据的代码
                //更新数据的时候使用handler
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        expand(helper.getAdapterPosition());
                    }
                });


                break;
            case ITEM_SECOND_LEVEL:
                final TaskBean item_temp2 = (TaskBean) item;
                helper.setText(R.id.tv_task_name, item_temp2.getName());
                helper.setText(R.id.tv_time, item_temp2.getCreate_time());
                //第一行隐藏段落线
                if(helper.getAdapterPosition() == 1 ){
                    helper.setVisible(R.id.view_tag, false);
                }

                //点击事件进入具体的列表详情
                helper.itemView.setOnClickListener(v -> {
                    Intent intent = new Intent(Utils.getApp(), TaskH5Activity.class);
                    intent.putExtra("task_info", item_temp2);
                    intent.putExtra("url", TASKDETAIL + "?id="+item_temp2.getId());
                    ActivityUtils.startActivity(intent);
                });

                TextView tv_sign = (TextView)helper.getView(R.id.tv_sign);
                if(item_temp2.getSign_number()==0){
                    helper.setText(R.id.tv_sign, "暂无打卡");
                }else {
                    helper.setText(R.id.tv_sign, item_temp2.getSign_number()+"/"+item_temp2.getNumber() +"已打卡");
                }




                break;
        }
    }


}
